<template>
  <div>
    <el-table :data="tableData" border style="width: 100%; margin-top: 20px">
      <el-table-column label="序号" width="180" type="index"> </el-table-column>
      <el-table-column prop="firstLevelPoint" label="一级指标">
      </el-table-column>
      <el-table-column prop="secondLevelPoint" label="二级指标">
      </el-table-column>
      <el-table-column prop="pointDesc" label="指标描述"></el-table-column>
      <el-table-column
        prop="achieveSummary"
        label="达成情况概述"
      ></el-table-column>
      <el-table-column prop="mainQuestion" label="主要问题"></el-table-column>
      <el-table-column prop="improveMethod" label="改进措施"></el-table-column>
      <el-table-column label="指标文件">
        <template slot-scope="scope">
          <el-button type="text" @click="preview(scope.row.certAttachmentId)">查看文件</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="isApprove(1, scope.row.id)"
            v-if="scope.row.expertAdviceStatus === 0"
            >肯定</el-button
          >
          <el-button
            type="text"
            @click="isApprove(2, scope.row.id)"
            v-if="scope.row.expertAdviceStatus === 0"
            >改进</el-button
          >
          <el-button
            type="text"
            @click="getCertInfo(scope.row.id, true, scope.row.expertAdvice)"
            v-if="scope.row.expertAdviceStatus === 2"
            >编辑</el-button
          >
          <el-button
            type="text"
            @click="getCertInfo(scope.row.id, false)"
            v-if="scope.row.expertAdviceStatus === 2"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-if="tableData.length > 0"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="page.pageNum"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="page.pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <el-row type="flex" justify="center" style="margin-top:20px">
      <el-col :span="4">
        <el-button type="primary" @click="isPass(1)">通 过</el-button>
        <el-button type="primary" @click="isPass(2)">驳 回</el-button>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="dialogVisible" width="30%">
      <span>这是一段信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
let Base64 = require('js-base64').Base64
export default {
  data() {
    return {
      tableData: [
        {
          firstLevel: "毕业要求",
          secondLevel: "师德规范",
          indexDescription: "践行社会主义和兴价值观",
          reach: "达成良好",
          problem: "加强规范",
          improvement: "加强规范",
          doc: "毕业要求文件"
        }
      ],
      page: {
        pageNum: 1,
        pageSize: 10
      },
      dialogVisible: false,
      totalPage: 0
    };
  },
  created() {
    this.getCert();
  },
  computed: {
    getId() {
      return this.$route.query.id;
    }
  },
  methods: {
     // 每页数
      sizeChangeHandle (val) {
        this.page.pageSize = val
        this.page.pageNum = 1
        this.getCert()
      },
      // 当前页
      currentChangeHandle (val) {
        this.page.pageNum = val
        this.getCert()
      },
    open() {
      this.$prompt("请输入内容", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "驳回成功"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入"
          });
        });
    },
    isPass(val) {
      if (val === 1) {
        this.$http({
          url: this.$http.reviewed("/admin/cert/"),
          method: "put",
          params: this.$http.adornParams(
            {
              certId: this.getId,
              status: val
            },
            false
          )
        }).then(res => {
          console.log(res);
        });
      } else {
        this.$prompt("请输入驳回理由", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消"
        })
          .then(({ value }) => {
            this.$http({
              url: this.$http.reviewed("/admin/cert/"),
              method: "put",
              params: this.$http.adornParams(
                {
                  certId: this.getId,
                  status: val,
                  remark: value
                },
                false
              )
            }).then(res => {
              console.log(res);
              this.$message({
                type: "success",
                message: "驳回成功"
              });
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消输入"
            });
          });
      }
    },
    // 获取页面数据
    getCert() {
      this.$http({
        url: this.$http.reviewed(`/admin/proDetailPage/${this.getId}`),
        method: "get",
        params: this.$http.adornParams(
          {
            ...this.page
          },
          false
        )
      }).then(res => {
        this.tableData = res.data.data.records;
        this.totalPage = res.data.data.total
      });
    },
    // 肯定还是改进
    isApprove(val, id) {
      if (val === 1) {
        this.$http({
          url: this.$http.reviewed("/admin/pro/expertAdvice"),
          method: "post",
          params: this.$http.adornParams(
            {
              certId: this.getId,
              status: val,
              proId: id,
              expertAdvice: ""
            },
            false
          )
        }).then(res => {
          this.getCert();
          this.$message({
            type: "success",
            message: "成功"
          });
        });
      } else {
        this.$prompt("请输入改进建议", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消"
        })
          .then(({ value }) => {
            this.$http({
              url: this.$http.reviewed("/admin/pro/expertAdvice"),
              method: "post",
              params: this.$http.adornParams(
                {
                  certId: this.getId,
                  status: val,
                  proId: id,
                  expertAdvice: value
                },
                false
              )
            }).then(res => {
              this.getCert();
              this.$message({
                type: "success",
                message: "成功"
              });
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消输入"
            });
          });
      }
    },
    // 通过还是驳回
    isPass(val) {
      if (val === 1) {
        this.$http({
          url: this.$http.reviewed("/admin/pro"),
          method: "put",
          params: this.$http.adornParams(
            {
              certId: this.getId,
              status: val
            },
            false
          )
        }).then(res => {
          this.$message({
            type: "success",
            message: "通过成功"
          });
          this.$router.go(-1);
        });
      } else {
        this.$prompt("请输入驳回理由", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消"
        })
          .then(({ value }) => {
            this.$http({
              url: this.$http.reviewed("/admin/pro"),
              method: "put",
              params: this.$http.adornParams(
                {
                  certId: this.getId,
                  status: val,
                  remark: value
                },
                false
              )
            }).then(res => {
              console.log(res);
              this.$message({
                type: "success",
                message: "驳回成功"
              });
              this.$router.go(-1);
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消输入"
            });
          });
      }
    },
    getCertInfo(id, val, expertAdvice) {
      if (val) {
        this.$prompt("请输入改进建议", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          inputValue: expertAdvice
        })
          .then(({ value }) => {
            this.$http({
              url: this.$http.reviewed("/admin/pro/expertAdvice"),
              method: "put",
              params: this.$http.adornParams(
                {
                  certId: this.getId,
                  proId: id,
                  expertAdvice: value
                },
                false
              )
            }).then(res => {
              this.getCert();
              this.$message({
                type: "success",
                message: "成功"
              });
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消输入"
            });
          });
      } else {
        this.$http({
          url: this.$http.reviewed(`/admin/proDetail/${this.getId}/${id}`),
          method: "get"
        }).then(res => {
          this.$alert(`${res.data.data.expertAdvice}`, "查看建议", {
            confirmButtonText: "确定",
            callback: () => {}
          });
        });
      }
    },
    preview(id) {
      this.$http({
          url:this.$http.fileUpload(`/file/admin/info/${id}`),
          method: "get"
        }).then(res => {
          window.open('https://file.keking.cn/onlinePreview?url='+encodeURIComponent(Base64.encode(res.data.data.path)))
        })
    }
  }
};
</script>

<style></style>
